package sv.ues.fia.adminperfildocentes.adapter;

import java.util.ArrayList;
import java.util.HashMap;

import sv.ues.fia.adminperfildocentes.R;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ListAdapter extends BaseAdapter {
	ArrayList<HashMap<String, String>> listIdiomas;
	private Activity activity;
	
	public ListAdapter(Activity activity, ArrayList<HashMap<String, String>> listIdiomas) {
		super();
		this.listIdiomas = listIdiomas;
		this.activity = activity;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listIdiomas.size();
	}

	@Override
	public String getItem(int position) {
		// TODO Auto-generated method stub
		return listIdiomas.get(position).get("nombre");
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return Long.valueOf(listIdiomas.get(position).get("id"));
	}

	public static class ViewHolder
	{
		public TextView txtViewId;
		public TextView txtViewTitle;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder view;
		LayoutInflater inflator = activity.getLayoutInflater();
		
		if(convertView==null)
		{
			view = new ViewHolder();
			convertView = inflator.inflate(R.layout.list_row, null);
			
			view.txtViewTitle = (TextView) convertView.findViewById(R.id.tituloRow);
			view.txtViewId = (TextView) convertView.findViewById(R.id.idRow);
			
			convertView.setTag(view);
		}
		else
		{
			view = (ViewHolder) convertView.getTag();
		}
		
		view.txtViewTitle.setText(listIdiomas.get(position).get("nombre"));
		view.txtViewId.setText(listIdiomas.get(position).get("id"));
		
		return convertView;
	}

}
